document.ready(function() {
    setValue('menuid', getUrlParam('menuid'));
    setValue('menuName', getUrlParam('menu'));
    setHtml('title', '功能操作项【所属菜单：' + getUrlParam('menu') + '】');

    queryKey('ok');
});

function queryKey(flag) {
    openLoad();

    var param = {};
    param.ctrl = 'account';
    param.func = 'getOperateList';
    param.menuid = getAjaxValue('menuid');

    sendAjax(param, function(result) {
        operate.list = result.operateList;
        setHtml('listCount', result.listCount);

        setDisplay('mainBg', '');
        closeLoad();
    });
}

function saveOperate() {
    if (isEmpty('keyword1') || isWicked('keyword1')) {
        showTip('代号格式错误');
        return;
    }
    if (isEmpty('keyword2') || isWicked('keyword2')) {
        showTip('名称格式错误');
        return;
    }

    var param = {};
    param.ctrl = 'account';
    param.func = 'saveOperate';
    param.menuid = getAjaxValue('menuid');
    param.code = getAjaxValue('keyword1');
    param.name = getAjaxValue('keyword2');

    sendAjax(param, function(result) {
        setValue('keyword1', '');
        setValue('keyword2', '');
        
        queryKey('ok');
    });
}

function deleteOperate(id, name) {
    setValue('tempid', id);

    openConfirm('确定删除 【' + name + '】 吗？', null, function() {
        var param = {};
        param.ctrl = 'account';
        param.func = 'deleteOperate';
        param.operateid = getAjaxValue('tempid');

        sendAjax(param, function(result) {
            queryKey('ok');
        });
    });
}